// pages/silverSendStatic/index.js

import {
  UserAccountModel
} from '../../models/userAccount.js'
let userAccountModel = new UserAccountModel()
const createRecycleContext = require('miniprogram-recycle-view')
let start = 0
let end = 0
let count = 0
Page({

  /**
   * 页面的初始数据
   */
  data: {
    senderId: 0,
    datas: [],
    initDate: '2020-01-01 00:00:00',
    startYear: 2019,
    endYear: 2050
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(start, end)
    // this.loadData(start, end)
  },

  search(){
    this.loadData(start, end)
  },
  loadData(start, end){
    let account = userAccountModel.adminSendSilverStatic(start, end)
    account.then(
      res => {
        // console.log(res)
        if (res && res.code == 1) {
          console.log(res)
          this.clearRecycleView(count)
          this.initRecycleView(res.data)
          count = res.data.length
        }else{
          console.log('暂无数据', count)
          this.clearRecycleView(count)
        }
      }
    ).catch(e => {
      console.log(e)
    });
  },
 
  initRecycleView(data) {
    var ctx = createRecycleContext({
      id: 'recycleId',
      dataKey: 'recycleList',
      page: this,
      itemSize: this.itemSizeFunc()
    })
    ctx.append(data)
    // ctx.update(0, data)
  },
  clearRecycleView(count){
    var ctx = createRecycleContext({
      id: 'recycleId',
      dataKey: 'recycleList',
      page: this,
      itemSize: this.itemSizeFunc()
    })
    // ctx.append(data)
    ctx.splice(0, count,this.data.datas)
  },

  itemSizeFunc: function (item, idx) {
    return {
      width: 350,
      height: 50
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  sendTimeToFather(e) {
    var data = e.detail.formatTime
    var format = data.replace(/-/g, '/')
    start = Date.parse(format) / 1000

  },
  sendTimeToFather1(e) {
    var data = e.detail.formatTime
    var format = data.replace(/-/g, '/')
    end = Date.parse(format) / 1000
  },
})